package com.woniu.postbar.controller;

import com.woniu.common.entity.PageData;
import com.woniu.common.entity.Result;
import com.woniu.postbar.entity.dto.PostCollectDTO;
import com.woniu.postbar.entity.vo.PostCollectVO;
import com.woniu.postbar.pojo.PostCollect;
import com.woniu.postbar.service.IPostCollectService;
import com.woniu.postbar.service.IUserPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wu
 * @since 2023-05-20
 */
@RestController
@RequestMapping("/postCollect")
@Api(tags = "收藏模块")
public class PostCollectController {

    @Autowired
    private IPostCollectService postCollectService;


    @PostMapping("/insert")
    @ApiOperation("新增收藏")
    public Result increase(@RequestBody PostCollect collect){
        Boolean flag = postCollectService.increaseCollect(collect);
        return Result.ok(flag);
    }

    @PostMapping("/deleteById/{id}")
    @ApiOperation("删除收藏")
    public Result decrease(@PathVariable Integer id){
        Boolean flag = postCollectService.deleteCollect(id);
        return Result.ok(flag);
    }

    @PostMapping("/searchPage/{currentPage}/{pageSize}")
    @ApiOperation("分页查询收藏")
    public Result<PageData<List<PostCollectVO>>> searchPage(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody PostCollectDTO collectDTO){
        PageData<List<PostCollectVO>> pageData = postCollectService.searchPage(currentPage,pageSize,collectDTO);
        return Result.ok(pageData);
    }
}
